﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using VisualEditorUILib;
using BusinessModule.Forms;

namespace GUserInterface
{

    public delegate void RefreshHandler ( string oldName );
    public delegate void UpdatePropertyGridHandler ( Form formToUpdate);
    public delegate void FormSaved( string title );

    [DefaultProperty("Title")]
    public partial class FormVEPanel : DockContent
    {


        #region Events

        public event RefreshHandler RefreshEvent;
        public event UpdatePropertyGridHandler UpdatePropertyGridEvent;
        public event FormSaved FormSavedEvent;

        #endregion

        #region Variables

        FormControlContainer fcc;
        FormEditorPanel panelEdt;

        #endregion

        #region Contruction

        public FormVEPanel( int r, int c)
        {
            InitializeComponent();
            fcc = new FormControlContainer(r, c);
            InitializeComponentCustom();
        }

        private void InitializeComponentCustom()
        {
            panelEdt = new FormEditorPanel(fcc);
            panel1.Controls.Add(panelEdt);
        }

        #endregion

        
        #region Properties

        public FormEditorPanel FEPanel
        {
            get { return panelEdt; }
            set { panelEdt = value; }
        }

        [Category("Dane podstawowe")]
        [DisplayName("Tytul Formy")]
        [Description("Tytul Formy w Designerze")]
        public String Title
        {
            get { return this.TabText; }
            set
            {
                string oldText = this.TabText;
                this.TabText = value;
                RefreshEvent(oldText);
            }
        }

        #endregion

        #region Methods

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //TU BEDZIE ZAPISANIE FORMY FORMCONTROLCONTAINER - SERIAZLIZACJA!!!
            FormSavedEvent(this.TabText);
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            UpdatePropertyGridEvent(this);
        }

        #endregion
    }
}
